package leetcodecompetition.D368;

/**
 * @Author: Siantar
 * @Date: 2023-10-22-10:34
 * @Description: 1.0
 */
public class T100114 {
    public int minimumSum(int[] nums) {
        int n = nums.length;
        if (n<3)return -1;
        int[] left = new int[n];
        int[] right = new int[n];
        for (int i = 0; i < n; i++) {
            left[i] = Math.min(i == 0 ? Integer.MAX_VALUE : left[i - 1], nums[i]);
        }
        for (int i = n - 1; i >= 0; i--) {
            right[i] = Math.min(i == n - 1 ? Integer.MAX_VALUE : right[i + 1], nums[i]);
        }
        int res = Integer.MAX_VALUE;
        for (int i = 1; i < n - 1; i++) {
            System.out.println(left[i-1] + " " + nums[i] + " " + right[i+1]);
            if (nums[i] > left[i-1] && nums[i] > right[i+1]) {
                res = Math.min(res, left[i-1] + nums[i] + right[i+1]);
            }
        }
        return res == Integer.MAX_VALUE ? -1 : res;
    }
}
